package com.honey.mybatis.generator.dependent;

import com.honey.compilation.java.AbstractJavaCompilation;
import com.honey.compilation.java.Field;
import com.honey.compilation.java.Method;
import com.honey.compilation.java.Parameter;
import com.honey.core.compiler.CompilationException;
import com.honey.core.dbmapping.introspect.IntrospectSchema;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.core.types.FullyQualifiedJavaType;
import com.honey.core.types.JDKFullyQualifiedJavaType;
import com.honey.mybatis.generator.MybatisPlugin;
import com.honey.mybatis.generator.dao.ProduceDaoImplements;
import com.honey.mybatis.generator.dao.field.CountField;
import com.honey.mybatis.generator.dao.field.DeleteByDynamicField;
import com.honey.mybatis.generator.dao.field.DeleteByPrimaryKeyField;
import com.honey.mybatis.generator.dao.field.ExistsField;
import com.honey.mybatis.generator.dao.field.InsertField;
import com.honey.mybatis.generator.dao.field.InsertSelectiveField;
import com.honey.mybatis.generator.dao.field.SelectAllField;
import com.honey.mybatis.generator.dao.field.SelectByDynamicField;
import com.honey.mybatis.generator.dao.field.SelectByPrimaryKeyField;
import com.honey.mybatis.generator.dao.field.UpdateByDynamicField;
import com.honey.mybatis.generator.dao.field.UpdateByDynamicSelectiveField;
import com.honey.mybatis.generator.dao.field.UpdateByPrimaryKeyField;
import com.honey.mybatis.generator.dao.field.UpdateByPrimaryKeySelectiveField;
import com.honey.mybatis.generator.dao.field.VirtualDeleteByDynamicField;
import com.honey.mybatis.generator.dao.field.VirtualDeleteByPrimaryKeyField;
import com.honey.mybatis.generator.dao.method.CountMethod;
import com.honey.mybatis.generator.dao.method.DeleteByDynamicMethod;
import com.honey.mybatis.generator.dao.method.DeleteByPrimaryKeyMethod;
import com.honey.mybatis.generator.dao.method.ExistsMethod;
import com.honey.mybatis.generator.dao.method.InsertMethod;
import com.honey.mybatis.generator.dao.method.InsertSelectiveMethod;
import com.honey.mybatis.generator.dao.method.SaveMethod;
import com.honey.mybatis.generator.dao.method.SelectAllMethod;
import com.honey.mybatis.generator.dao.method.SelectByDynamicMethod;
import com.honey.mybatis.generator.dao.method.SelectByPrimaryKeyMethod;
import com.honey.mybatis.generator.dao.method.SelectOneByDynamicMethod;
import com.honey.mybatis.generator.dao.method.UpdateByDynamicMethod;
import com.honey.mybatis.generator.dao.method.UpdateByDynamicSelectiveMethod;
import com.honey.mybatis.generator.dao.method.UpdateByPrimaryKeyMethod;
import com.honey.mybatis.generator.dao.method.UpdateByPrimaryKeySelectiveMethod;


/**
 * 继承模型下ProduceBaseDao处理方式
 * @author Administrator
 *
 */
public class ProduceInjectionDependentDaoImplements extends ProduceDaoImplements implements Dependent{

	public ProduceInjectionDependentDaoImplements(MybatisPlugin mybatisPlugin,
			IntrospectSchema introspectSchema,
			IntrospectSchemaColumn introspectSchemaColumn) {
		super(mybatisPlugin, introspectSchema, introspectSchemaColumn);
	}
	
	@Override
	public AbstractJavaCompilation produceCompilation() throws CompilationException {
		AbstractJavaCompilation answer = super.produceCompilation();
		FullyQualifiedJavaType type =  answer.getSuperClass() ;
		answer.setSuperClass((FullyQualifiedJavaType)null);
		Field field = new Field("baseMybatisdao",type);
		answer.addField(field);
		Method method = new Method("setBaseMybatisdao");
		method.addParameter(new Parameter(type,"baseMybatisdao"));
		method.addBodyLine("this.baseMybatisdao = baseMybatisdao ");
		answer.addMethod(method);
		return answer;
	}

	@Override
	public Field[] produceFields() throws CompilationException {
		return new Field[]{
			new CountField().createField(),
			new SelectAllField().createField(),
			new SelectByPrimaryKeyField().createField(),
			new SelectByDynamicField().createField(),
			new DeleteByPrimaryKeyField().createField(),
			new VirtualDeleteByPrimaryKeyField(mybatisPlugin, introspectSchema, introspectSchemaColumn).createField(),
			new DeleteByDynamicField().createField(),
			new VirtualDeleteByDynamicField(mybatisPlugin, introspectSchema, introspectSchemaColumn).createField(),
			new InsertField().createField(),
			new InsertSelectiveField().createField(),
			new UpdateByPrimaryKeyField().createField(),
			new UpdateByPrimaryKeySelectiveField().createField(),
			new UpdateByDynamicSelectiveField().createField(),
			new UpdateByDynamicField().createField(),
			new ExistsField().createField(),
			
		};
	}
	
	public Method[] produceMethods() throws CompilationException {
		AbstractJavaCompilation abstractJavaCompilation = super.getAbstractJavaCompilation();
		//Method[] baseMethod = super.produceMethods();
		Method[] answer = new Method[]{
				new CountMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn).createMethod() ,
				new CountMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true).createMethod(),
				
				new ExistsMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn).createMethod() ,
				new ExistsMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true).createMethod(),
				
				new SelectByPrimaryKeyMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn).createMethod() ,
				new SelectByPrimaryKeyMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true).createMethod(),
			
				new SelectAllMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn).createMethod(),
				new SelectAllMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,false,true).createMethod(),
				new SelectAllMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true,false).createMethod(),
				new SelectAllMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true,true).createMethod(),
				
				new SelectByDynamicMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn).createMethod(),
				new SelectByDynamicMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,false,true).createMethod(),
				new SelectByDynamicMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true,false).createMethod(),
				new SelectByDynamicMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true,true).createMethod(),
				
				new SelectOneByDynamicMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn).createMethod(),
				new SelectOneByDynamicMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true).createMethod(),
				
				new DeleteByDynamicMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn).createMethod(),
				new DeleteByDynamicMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true).createMethod(),
				
				new DeleteByPrimaryKeyMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn).createMethod(),
				new DeleteByPrimaryKeyMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true).createMethod(),

				new InsertMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn).createMethod(),
				new InsertMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true).createMethod(),
				
				new InsertSelectiveMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn).createMethod(),
				new InsertSelectiveMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true).createMethod(),
				
				new SaveMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn).createMethod(),
				new SaveMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true).createMethod(),
				
				new UpdateByPrimaryKeyMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn).createMethod(),
				new UpdateByPrimaryKeyMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true).createMethod(),
				
				new UpdateByPrimaryKeySelectiveMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn).createMethod(),
				new UpdateByPrimaryKeySelectiveMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true).createMethod(),
				
				new UpdateByDynamicSelectiveMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn).createMethod(),
				new UpdateByDynamicSelectiveMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true).createMethod(),
				
				new UpdateByDynamicMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn).createMethod(),
				new UpdateByDynamicMethod(abstractJavaCompilation, mybatisPlugin, introspectSchema, introspectSchemaColumn,true).createMethod(),
				
				
		};
		//Method[] answer = new Method[ baseMethod.length + enxtend.length ] ; 
		//System.arraycopy(baseMethod, 0, answer, 0, baseMethod.length);
		//System.arraycopy(enxtend, 0, answer, baseMethod.length, enxtend.length);
		
		return answer;
	}

	/* (non-Javadoc)
	 * @see com.honey.mybatis.generator.dao.ProduceDaoImplements#produceImportClass()
	 */
	@Override
	public FullyQualifiedJavaType[] produceImportClass()
			throws CompilationException {
		return new FullyQualifiedJavaType[]{
			JDKFullyQualifiedJavaType.getHashMapInstance(),
			JDKFullyQualifiedJavaType.getMapInstance(),
		};
	}
}
